/********************
 * 海外安全认证、身份认证	*
 ********************/

/**
 * 重发验证邮件
 */
function resendEmail(){
	var emailTypeInput = document.getElementById("emailType");
	var emailType = 0;
	if(emailTypeInput){
		emailType = emailTypeInput.value;
	}
	window.location.href = "/user/resendEmailConfirm.do?type="+emailType+"&random="+Math.round(Math.random()*100);
}


/**
 * 手机验证
 */
function phoneValidate(){
	dialogBoxShadow(false);
	document.getElementById("foreignPhoneValidate").style.display = "block";
	addMoveEvent("dialog_title","dialog_content");
}

/**
 * 关闭手机验证
 */
function closeForeignPhoneValidate(){
	dialogBoxHidden();
	document.getElementById("foreignPhoneValidate").style.display = "none";
}

/**
 * 绑定邮箱弹层
 */
function showBindEmailValidate(){
	dialogBoxShadow(false);
	document.getElementById("bindEmailValidate").style.display = "block";
	addMoveEvent("dialog_title2","dialog_content2");
}

/**
 * 关闭绑定邮箱弹层
 */
function closeBindEmailValidate(){
	dialogBoxHidden();
	document.getElementById("bindEmailValidate").style.display = "none";
}

/**
 * 基本信息验证
 */
function infoValidate(flag){
    if(flag==1) {
        window.location.href = "/user/companyIdentity.do?random="+Math.round(Math.random()*100);
    }else {
        window.location.href = "/user/foreignBaseIdentity.do?random="+Math.round(Math.random()*100);
    }
}

/**
 * 海外身份信息验证
 */
function foreignIDValidate(papersType){
	window.location.href = "/user/idDocument.do?papersType="+papersType+"&random="+Math.round(Math.random()*100);
}
/**
 * 海外身份信息验证
 */
function foreignIDValidateCN(papersType){
	window.location.href = "/user/residenceDocument.do?&cn="+1+"&papersType="+papersType+"&random="+Math.round(Math.random()*100);
}

/**
 * 切换美国国籍
 */
var whitelist = [40,161,8,26,34,87,118,166,167];
var whitelistcountry = ["China","Singapore","Argentina","Brazil","Canada","Italy","Mexico","South Africa","Spain"];
var whitelistmapping = ["ID Number","NRIC","DNI","CPF","SIN","Codice Fiscale","RFC","ID Card Number","NIF"];
var whitelistplaceholder = ["","","Documento Nacional de Identidad","Cadastro de Pessoas Físicas","Social Insurance Number","","Registro Federal de Contribuyentes","","Número de Identificación Fiscal"];
function switchUsaNationality(optionValue){
    var limitedCountries = document.getElementById('limitedCountryIds').value;
    if(limitedCountries.indexOf(","+optionValue+",")>=0) {
        document.getElementById('cannotverify').style.display='block';
    }else {
        document.getElementById('cannotverify').style.display='none';
    }
    //以下国家不支持双重国籍(选美国国籍时也隐藏nousanationality选项)
	if(",4,11,12,14,25,28,39,40,50,51,55,60,62,81,82,83,89,91,92,93,95,96,99,105,111,117,118,126,129,130,135,140,142,144,161,162,164,178,190,192,197,201,".indexOf(","+optionValue+",")>=0){
        document.getElementById('nousanationalityLi').style.display='none';
	}else{
		document.getElementById('nousanationalityLi').style.display='block';
	}
	if (optionValue == 0){
        jQuery("#passportDiv").hide();
    }else{
        jQuery("#passportDiv").show();
    }
    if (optionValue == 40 && site_flag == 2){
        // 国际站选择中国认证时提示功能限制
        var callback = {okBack:function(){},noBack:function(){}};
        var tips = "<span>"+get$('limitchineseuserfunction')+"</span><br>"
            + "<span>1．"+get$('limitchineseuserfuture')+"</span><br>"
            + "<span>2．"+get$('limitchineseuserwithdrawusd')+"</span>";
        okcoinAlert(tips, false, callback);
    }

    //不同国家身份证显示不一样
    /*var isInWhitelist = false;
    var whitemapping = "";
    var whiteplaceholder = "";
    for(var i=0;i<whitelist.length;i++){
        if(optionValue == whitelist[i]){
            isInWhitelist = true;
            whitemapping = whitelistmapping[i];
            whiteplaceholder = whitelistplaceholder[i];
            break;
        }
    }*/
//    if(isInWhitelist){
//        document.getElementById('nopassportDiv').style.display='block';
//        document.getElementById('idNumberDiv').style.display='block';
        //英文情况下面才显示不同国家身份证的简写
//        if(document.getElementById('languagetype').value==1){
//            document.getElementById('idNumberTitle').innerHTML = whitemapping+":";
//            document.getElementById('idNumber').placeholder = whiteplaceholder;
//        }else {
//            document.getElementById('idNumberTitle').innerHTML = "身份证号"+":";
//            document.getElementById('idNumber').placeholder = whitemapping;
//        }
//    }
//    else{
//        document.getElementById('nopassportDiv').style.display='none';
//        document.getElementById('idNumberDiv').style.display='none';
//    }
}

/**
 * 切换护照与身份证
 */
function switchPassportOrIddocument(checked){
	if(checked){
		document.getElementById('passportDiv').style.display='none';
	}else{
		document.getElementById('passportDiv').style.display='block';
	}
}

/**
 * 时间验证
 */
function validDateIpt(dateName) {
    jQuery(dateName).val("");
    var box = jQuery(dateName).parent().find(".dateinput_box");
    var year = jQuery(box).find(".year_value").val();
    var month = jQuery(box).find(".month_value").val();
    var dvalue = jQuery(box).find(".day_value").val();
    if(year!=""&&month!="") {
        var days = new Date(year,month,0).getDate();
        for(var i=1;i<=days;++i) {
            if(dvalue==i) {
                month = month.length>1 ? month : "0"+month;
                dvalue = dvalue.length>1 ? dvalue : "0"+dvalue;
                jQuery(dateName).val(year+"-"+month+"-"+dvalue);
                return;
            }
        }
    }
}

/**
 * 提交
 */
function submitForeignIdentity(){
	//时间控件
    validDateIpt("#birthDate");
    //validDateIpt("#startDate");
    //validDateIpt("#endDate");
    //出生日期
	var birthDate = document.getElementById("birthDate").value;
	if(birthDate == ""){
		document.getElementById("errorMessage").innerHTML = get$("foreignIdentitybirthdate");
		return;
	}else{
		var y = birthDate.substr(0,4);
		var m = birthDate.substr(5,2);
		var d = birthDate.substr(8,2);
		var nowday = new Date();
		var month = parseInt(m)-1;
		var birthday = new Date(y, month, d);
		age = nowday.getFullYear() - birthday.getFullYear() - ((nowday.getMonth() < birthday.getMonth() || nowday.getMonth() == birthday.getMonth() && nowday.getDate() < birthday.getDate()) ? 1 : 0);
		if(age<18){
			document.getElementById("errorMessage").innerHTML = get$("peopleunder18");
			return;
		}
	}
    //姓
	var firstName = document.getElementById("firstName").value;
	if(firstName == ""){
		document.getElementById("errorMessage").innerHTML = get$("foreignIdentityfirstname");
		return;
	}
	if(firstName.length >= 100){
		document.getElementById("errorMessage").innerHTML = get$("foreignIdentityfirstnameislong");	
    	return;
	}
	//名
	var lastName = document.getElementById("lastName").value;
	if(lastName == ""){
		document.getElementById("errorMessage").innerHTML = get$("foreignIdentitylastname");
		return;
	}
	if(lastName.length >= 100){
		document.getElementById("errorMessage").innerHTML = get$("foreignIdentitylastnameislong");
    	return;
	}
    //曾用名、别名
    var previousName = document.getElementById("previousName").value;
    if(previousName.length >= 100){
        document.getElementById("errorMessage").innerHTML = get$("foreignIdentitylastnameislong");
        return;
    }
    //真实姓名
	var realName = document.getElementById("realName").value;
	if(realName == ""){
		document.getElementById("errorMessage").innerHTML = get$("foreignIdentityrealname");
    	return;
	}
	if(realName.length >= 100){
		document.getElementById("errorMessage").innerHTML = get$("foreignIdentityrealnameislong");
    	return;
	}
	//国籍
	var country = document.getElementById("country").value;
    var limitedCountries = document.getElementById('limitedCountryIds').value;
    if(limitedCountries.indexOf(","+country+",")>=0) {
        document.getElementById("errorMessage").innerHTML = get$("foreignIdentitycannotverify");
        return;
    }
	//无美国国籍
	var nousanationality = document.getElementById("nousanationality").checked;
	if(country == 192){
		nousanationality = 1;
	}else{
		if(document.getElementById("nousanationality").checked){
			nousanationality = 0;
		}else{
			nousanationality = 1;
		}
	}
    if(",4,11,12,14,25,28,39,40,50,51,55,60,62,81,82,83,89,91,92,93,95,96,99,105,111,117,118,126,129,130,135,140,142,144,161,162,164,178,190,197,201,".indexOf(","+country+",")>=0) {
        nousanationality = 0;
    }
	
	//护照号
	var passport = trim(document.getElementById("passport").value);
	if(passport == ""){
		document.getElementById("errorMessage").innerHTML = get$("foreignIdentitypassport");
		return;
	}else{
		document.getElementById("errorMessage").innerHTML = "&nbsp;";
	}
	if(passport.length <= 5){
		document.getElementById("errorMessage").innerHTML = get$("foreignIdentitypassportisshort");
    	return;
	}
	if(passport.length >= 30){
		document.getElementById("errorMessage").innerHTML = get$("foreignIdentitypassportislong");	
    	return;
	}
		//发证日期
//		var startDate = document.getElementById("startDate").value;
//		if(startDate == ""){
//			document.getElementById("errorMessage").innerHTML = get$("foreignIdentitystartdate");
//			return;
//		}
//		//截止日期
//		var endDate = document.getElementById("endDate").value;
//		if(endDate == ""){
//			document.getElementById("errorMessage").innerHTML = get$("foreignIdentityenddate");
//			return;
//		}
		//验证护照时间
//		if(startDate>=endDate){
//			document.getElementById("errorMessage").innerHTML = get$("foreignIdentitystartdatebigthanenddate");
//			return;
//		}
	
	//有无身份证（为美国，和10以内的国籍才显示）
	/*var isInWhitelist = false;
	for(var i=0;i<whitelist.length;i++){
		if(country == whitelist[i]){
			isInWhitelist = true;
			break;
		}
	}
	if(isInWhitelist){
		//身份证号
		var idNumber = trim(document.getElementById("idNumber").value);
		if(idNumber == ""){
			document.getElementById("errorMessage").innerHTML = get$("foreignIdentityidnumber");
			return;
		}else{
			document.getElementById("errorMessage").innerHTML = "&nbsp;";
		}
		if(idNumber.length <= 5){
			document.getElementById("errorMessage").innerHTML = get$("foreignIdentityidnumberisshort");
	    	return;
		}
		if(idNumber.length >= 20){
			document.getElementById("errorMessage").innerHTML = get$("foreignIdentityidnumberislong");	
	    	return;
		}
		//中国用户得验证其身份证帐号
		if(country==40&&!identityCheck(idNumber)){
            document.getElementById("errorMessage").innerHTML = get$("wrongidnumber");
            return;
		}
	}*/
	
	//当前住址
	var address = document.getElementById("address").value;
    //邮编（非必填）
    var postcode = trim(document.getElementById("postcode").value);
//    if(postcode==""&&",8,10,11,26,34,51,68,85,87,106,118,130,131,135,166,167,172,173,191,192,".indexOf(","+address+",")>=0) {
//        document.getElementById("errorMessage").innerHTML = get$("inputrightpostcodenotnull");
//        return;
//    }
    if(postcode == ""){
    	document.getElementById("errorMessage").innerHTML = get$("inputrightpostcodenotnull");
        return;
    }
    if(postcode.length < 4){
        document.getElementById("errorMessage").innerHTML = userindexjs51;
        return;
    }
    if(postcode.length > 15){
        document.getElementById("errorMessage").innerHTML = userindexjs48;
        return;
    }
    
	//建筑号
    var build = trim(document.getElementById("build").value);
    if(build != ""){
        if(build.length >= 100){
            document.getElementById("errorMessage").innerHTML = get$("foreignIdentitybuildislong");
            return;
        }
    }
    //街道
    var street = trim(document.getElementById("street").value);
    if(street == ""){
        document.getElementById("errorMessage").innerHTML = userindexjs41;
        return;
    }
    if(street.length >= 150){
        document.getElementById("errorMessage").innerHTML = userindexjs42;
        return;
    }
    //单元号
    var unit = trim(document.getElementById("unit").value);
    if(unit != ""){
        if(unit.length >= 100){
            document.getElementById("errorMessage").innerHTML = get$("foreignIdentityunitislong");
            return;
        }
    }
    //城市
    var city = trim(document.getElementById("city").value);
    if(city == ""){
        document.getElementById("errorMessage").innerHTML = userindexjs49;
        return;
    }
    if(city.length >= 100){
        document.getElementById("errorMessage").innerHTML = userindexjs50;
        return;
    }
    //省份
    var province = trim(document.getElementById("province").value);
    if(province == ""){
        document.getElementById("errorMessage").innerHTML = userindexjs43;
        return;
    }
    if(province.length >= 100){
        document.getElementById("errorMessage").innerHTML = userindexjs44;
        return;
    }
    
    var detailAddress = "";
//    if(!document.getElementById("detailAddress")) {
//    	document.getElementById("errorMessage").innerHTML = get$("inputaddressinfodetail");
//    	return;
//	}
//	detailAddress = document.getElementById("detailAddress").value;
//	if(detailAddress=="") {
//		document.getElementById("errorMessage").innerHTML = get$("inputaddressinfodetail");
//		return;
//	}

	//提交
	var url = "/user/foreignIdentityValidate.do?random="+Math.round(Math.random()*100);
    var param={firstName:firstName,lastName:lastName,previousName:previousName,realName:realName,birthDate:birthDate,country:country,nousanationality:nousanationality,
        passport:passport,address:address,postcode:postcode,detailAddress:detailAddress,province:province,street:street,city:city,build:build,unit:unit};
    jQuery.post(url,param,function(data){
    	var result = eval('(' + data + ')');
		if(result!=null){
			if(result == -1){
				//非法的请求
				window.location.href= document.getElementById("coinMainUrl").value+"/";
			}else if(result == 0){
				//提交失败
				document.getElementById("errorMessage").innerHTML= get$("rechargeusdsubfailure");
			}else if(result == 1){
				//提交成功
				window.location.href= document.getElementById("coinMainUrl").value+"/user/foreignIndex.do";
			}else if(result == 111){
                //提交成功
                var papersType = document.getElementById("papersType").value;
                window.location.href = document.getElementById("coinMainUrl").value+"/user/residenceDocument.do?papersType="+papersType+"&random="+Math.round(Math.random()*100);
            }else if(result == 1111){
                //提交成功
                window.location.href= document.getElementById("coinMainUrl").value+"/user/userinfo.do";
            }else if(result == 2){
				//姓
				document.getElementById("errorMessage").innerHTML= get$("foreignIdentityfirstnameislong");
			}else if(result == 3){
				//名
				document.getElementById("errorMessage").innerHTML= get$("foreignIdentitylastnameislong");
			}else if(result == 21){
                //曾用名、别名
                document.getElementById("errorMessage").innerHTML= get$("foreignIdentitypreviousnameislong");
            }else if(result == 4){
				//真实姓名
				document.getElementById("errorMessage").innerHTML= get$("foreignIdentityrealnameislong");
			}else if(result == 5){
				//出生日期
				document.getElementById("errorMessage").innerHTML= get$("foreignIdentitybirthdate");
			}else if(result == 6){
				//护照号
				document.getElementById("errorMessage").innerHTML= get$("foreignIdentitypassportislong");
			}else if(result == 7){
				//发证日期
				document.getElementById("errorMessage").innerHTML= get$("foreignIdentitystartdate");
			}else if(result == 8){
				//截止日期
				document.getElementById("errorMessage").innerHTML= get$("foreignIdentityenddate");
			}else if(result == 9){
				//身份证号
				document.getElementById("errorMessage").innerHTML= get$("foreignIdentityidnumberislong");	
			}else if(result == 10){
				//验证省份
				document.getElementById("errorMessage").innerHTML= userindexjs44;
			}else if(result == 11){
				//验证街道
				document.getElementById("errorMessage").innerHTML= userindexjs42;
			}else if(result == 12){
				//验证城市
				document.getElementById("errorMessage").innerHTML= userindexjs50;
			}else if(result == 13){
				//验证建筑号
				document.getElementById("errorMessage").innerHTML= get$("foreignIdentitybuildislong");
			}else if(result == 14){
				//验证单元号
				document.getElementById("errorMessage").innerHTML= get$("foreignIdentityunitislong");
			}else if(result == 15){
				//验证邮编
				document.getElementById("errorMessage").innerHTML= userindexjs48;
			}else if(result == 16){
				//中国用户身份证验证
				document.getElementById("errorMessage").innerHTML= get$("wrongidnumber");
			}else if(result == 17) {
                document.getElementById("errorMessage").innerHTML= get$("inputrightpostcodenotnull");
            }else if(result == 18) {
                document.getElementById("errorMessage").innerHTML= get$("inputaddressinfodetail");
            }else if(result == 19) {
                document.getElementById("errorMessage").innerHTML = get$("foreignIdentitycannotverify");
            }else if(result == 20) {
            	document.getElementById("errorMessage").innerHTML = get$("peopleunder18");
            }else if(result == 22){
                //护照号重复
                document.getElementById("errorMessage").innerHTML = get$("passportisused");
            }else if(result == 23){
                //持仓用户不能认证中国国籍
                document.getElementById("errorMessage").innerHTML = get$("verificationchineseuserholdfuture");
            }
		}
    });
}

/*简单校验身份证号码位数的正确性*/
function identityCheck(card){
    // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
    if(null == card || ""==card){
        return false;
    }
    var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    if(reg.test(trim(card))){
        return  true;
    }else{
        return  false;
    }
}

/**
 *
 */
function submitVerifySuccessW(){
	jQuery("#rechargeVerifyContent").hide();
	jQuery("#verifySuccessContent").show();
	setInterval('window.location.reload()',3000);
}
function submitVerifySuccessTocharge(){
	jQuery("#rechargeVerifyContent").hide();
	jQuery("#verifySuccessContent").show();
	setInterval('window.location.href=document.getElementById("coinMainUrl").value+"/account/rechargeCny.do"',3000);
}
/**
 * 提交
 */
function submitChinaIdentity(){

    //时间控件
    validDateIpt("#birthDate");

    //姓
    var realName = document.getElementById("realName").value;
    if(realName == ""){
        document.getElementById("errorMessage").innerHTML = get$("notEmptyRealName");//真是姓名
        return;
    }
    if(realName.length >= 100){
        document.getElementById("errorMessage").innerHTML = "姓名过长.";//get$("foreignIdentityfirstnameislong");
        return;
    }
    
    //国籍
    var country = document.getElementById("country").value;
    //出生日期
    var birthDate = document.getElementById("birthDate").value;
	//地点
	var verifyType = 0;
	if(document.getElementById("personalVerifyPosition")){
		verifyType  = document.getElementById("personalVerifyPosition").value;
	}

    if(country=="40"){//国内用户
        //身份证号
        var idNumber = trim(document.getElementById("idNumber").value);
        if(idNumber == ""){
            document.getElementById("errorMessage").innerHTML = get$("notEmptyIdNumber");
            return;
        }else{
            document.getElementById("errorMessage").innerHTML = "&nbsp;";
        }
        if(idNumber.length <= 5){
            document.getElementById("errorMessage").innerHTML = get$("wrongidnumber");
            return;
        }
        if(idNumber.length >= 20){
            document.getElementById("errorMessage").innerHTML = get$("wrongidnumber");
            return;
        }
        if(!identityCheck(idNumber)){
            document.getElementById("errorMessage").innerHTML = get$("wrongidnumber");
            return;
        }
    }else{
        //护照号
        var passport = trim(document.getElementById("passport").value);
        if(passport == ""){
            document.getElementById("errorMessage").innerHTML = get$("entryPassportNum");
            return;
        }else{
            document.getElementById("errorMessage").innerHTML = "&nbsp;";
        }
        if(passport.length <= 5){
            document.getElementById("errorMessage").innerHTML = get$("wrongpassportnumber");
            return;
        }
        if(passport.length >= 20){
            document.getElementById("errorMessage").innerHTML = get$("wrongpassportnumber");
            return;
        }
        // 身份证用户不用选择生日，护照用户需要
        if(birthDate == ""){
            document.getElementById("errorMessage").innerHTML = get$("notEmptyBirthday");
            return;
        }
        //发证日期
//        var startDate = document.getElementById("startDate").value;
//        if(startDate == ""){
//            document.getElementById("errorMessage").innerHTML = get$("notEmptyIssuedDate");
//            return;
//        }
        //截止日期
//        var endDate = document.getElementById("endDate").value;
//        if(endDate == ""){
//            document.getElementById("errorMessage").innerHTML = get$("notEmptyExpiredDate");
//            return;
//        }
        //验证护照时间
//		if(startDate>=endDate){
//			document.getElementById("errorMessage").innerHTML = get$("foreignIdentitystartdatebigthanenddate");
//			return;
//		}
    }
    document.getElementById("errorMessage").innerHTML = "&nbsp;";
	//点击按钮后让其置灰不可点并出现动态小点点
    var buttonValue = document.getElementById("submitChinaIdentityBtn").value;		//先前按钮的值
	waitingStation("submitChinaIdentityBtn",get$("insubmiting"));
    //提交
    var url = "/user/chinaIdentityValidate.do?random="+Math.round(Math.random()*100);
    var param={realName:realName,birthDate:birthDate,country:country,passport:passport,idNumber:idNumber};
    jQuery.post(url,param,function(data){
        var result = eval('(' + data + ')');
        if(result!=null){
            if(result == -1){
                //非法的请求
                window.location.href= document.getElementById("coinMainUrl").value+"/";
            }else if(result == 0){
                //提交失败
                document.getElementById("errorMessage").innerHTML="提交失败";
                //恢复按钮让其可点击并去掉小点点
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 1){
                //提交成功
				if(verifyType==1){
					jQuery("#closeRechargeVerifyPop").hide();
					submitVerifySuccessW();
				}else{
					//window.location.href= document.getElementById("coinMainUrl").value+"/user/userinfo.do?perType=1";
					showChinalVerifyPop();
					submitVerifySuccessTocharge();
				}
            }else if(result == 4){
                //真实姓名
                document.getElementById("errorMessage").innerHTML= get$("notEmptyRealName");
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 5){
                //出生日期
                document.getElementById("errorMessage").innerHTML= get$("notEmptyBirthday");
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 6){
                //护照号
                document.getElementById("errorMessage").innerHTML= get$("entryPassportNum");
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 7){
                //发证日期
                document.getElementById("errorMessage").innerHTML= get$("notEmptyIssuedDate");
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 8){
                //截止日期
                document.getElementById("errorMessage").innerHTML= get$("notEmptyExpiredDate");
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 9){
                //身份证号
                document.getElementById("errorMessage").innerHTML= get$("notEmptyIdNumber");
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 10){
                //身份证号
                document.getElementById("errorMessage").innerHTML= get$("wrongidnumber");
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 11){
                //身份证号重复
                document.getElementById("errorMessage").innerHTML= get$("idnumberisused");
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 12){
                //年龄限制
                document.getElementById("errorMessage").innerHTML= get$("yearoldover");
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 13){
                //国家限制
                document.getElementById("errorMessage").innerHTML = get$("foreignIdentitycannotverify");
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 14){
                //护照号重复
                document.getElementById("errorMessage").innerHTML = get$("passportisused");
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 15){
                //需要进行滑动验证码校验
                document.getElementById("geetestButton").click();
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }else if(result == 16){
                //认证次数限制
                document.getElementById("errorMessage").innerHTML = get$("userindexjs57");
                cancelWaiting("submitChinaIdentityBtn",buttonValue);
            }
        }
    });
}

/**
 * 身份证或者护照
 */
function isPassport(countryCode){
    if(countryCode=="40"){
    	document.getElementById('idNumberDiv').style.display='block';
        document.getElementById('passportDiv').style.display='none';
        document.getElementById('birthDateDiv').style.display='none';
    }else{
    	document.getElementById('idNumberDiv').style.display='none';
        document.getElementById('passportDiv').style.display='block';
        document.getElementById('birthDateDiv').style.display='block';
    }
}

/*------------------------解决IE不支持placeholder属性的问题（2014-10-16 by lz）-----------------------*/
jQuery.fn.placeholder = function(){
    var i = document.createElement('input'),placeholdersupport = 'placeholder' in i;
    if(!placeholdersupport){
        var inputs = jQuery(this);
        inputs.each(function(){
            var input = jQuery(this),
                text = input.attr('placeholder'),
                pdl = 0,
                height = input.outerHeight(),
                width = input.outerWidth(),
                placeholder = jQuery('<span class="phTips">'+text+'</span>');
            try{
                pdl = input.css('padding-left').match(/\d*/i)[0] * 1;
            }catch(e){
                pdl = 5;
            }
            placeholder.css({'margin-left': -(width-pdl),'height':height,'line-height':height+"px",'position':'absolute', 'color': "#cecfc9", 'font-size' : "12px"});
            placeholder.click(function(){
                input.focus();
            });
            if(input.val() != ""){
                placeholder.css({display:'none'});
            }else{
                placeholder.css({display:'inline'});
            }
            placeholder.insertAfter(input);
            input.keyup(function(e){
                if(jQuery(this).val() != ""){
                    placeholder.css({display:'none'});
                }else{
                    placeholder.css({display:'inline'});
                }
            });
        });
    }
    return this;
};

function submitCompanyIdentity(){
    //时间控件
    validDateIpt("#birthDate");
    //英文名
    var firstName = document.getElementById("firstName").value;
    if(firstName == ""){
        document.getElementById("errorMessage").innerHTML = get$("companyidentityjs4");
        return;
    }
    if(firstName.length >= 100){
        document.getElementById("errorMessage").innerHTML = get$("companyidentityjs1");
        return;
    }
    //真实姓名
    var realName = "";
	if(document.getElementById("realName")){
		realName = document.getElementById("realName").value;
		if(realName == ""){
			document.getElementById("errorMessage").innerHTML = get$("companyidentityjs8");
		    return;
		}
	}
	if(realName != ""){
		if(realName.length >= 100){
			document.getElementById("errorMessage").innerHTML = get$("companyidentityjs5");
			return;
		}
	}
    //注册日期
    var birthDate = document.getElementById("birthDate").value;
    if(birthDate == ""){
        document.getElementById("errorMessage").innerHTML = get$("companyidentityjs6");
        return;
    }
    //国籍
    var country = "";
	if(document.getElementById("country")){
		country = document.getElementById("country").value
	}

    //注册号
    var idNumber = trim(document.getElementById("idNumber").value);
    if(idNumber == ""){
        document.getElementById("errorMessage").innerHTML = get$("companyidentityjs7");
        return;
    }else{
        document.getElementById("errorMessage").innerHTML = "&nbsp;";
    }
    //建筑号
    var build = trim(document.getElementById("build").value);
    if(build != ""){
        if(build.length >= 100){
            document.getElementById("errorMessage").innerHTML = get$("foreignIdentitybuildislong");
            return;
        }
    }
    if(build.length >= 100){
        document.getElementById("errorMessage").innerHTML = get$("foreignIdentitybuildislong");
        return;
    }
    //街道
    var street = trim(document.getElementById("street").value);
    if(street == ""){
        document.getElementById("errorMessage").innerHTML = userindexjs41;
        return;
    }
    if(street.length >= 150){
        document.getElementById("errorMessage").innerHTML = userindexjs42;
        return;
    }
    //单元号
    var unit = trim(document.getElementById("unit").value);
    if(unit != ""){
        if(unit.length >= 100){
            document.getElementById("errorMessage").innerHTML = get$("foreignIdentityunitislong");
            return;
        }
    }
    //城市
    var city = trim(document.getElementById("city").value);
    if(city == ""){
        document.getElementById("errorMessage").innerHTML = userindexjs49;
        return;
    }
    if(city.length >= 100){
        document.getElementById("errorMessage").innerHTML = userindexjs50;
        return;
    }
    //省份
    var province = trim(document.getElementById("province").value);
    if(province == ""){
        document.getElementById("errorMessage").innerHTML = userindexjs43;
        return;
    }
    if(province.length >= 100){
        document.getElementById("errorMessage").innerHTML = userindexjs44;
        return;
    }
    //邮编
    var postcode = trim(document.getElementById("postcode").value);
    if(postcode == ""){
        document.getElementById("errorMessage").innerHTML = userindexjs47;
        return;
    }
    if(postcode.length < 4){
        document.getElementById("errorMessage").innerHTML = userindexjs51;
        return;
    }
    if(postcode.length > 15){
        document.getElementById("errorMessage").innerHTML = userindexjs48;
        return;
    }
    //曾用名
    var previousName = "";
    if(document.getElementById("previousName")){
    	previousName = trim(document.getElementById("previousName").value);
    }
    if(previousName != ""){
        if(previousName.length >= 100){
            document.getElementById("errorMessage").innerHTML = get$("userindexjs52");
            return;
        }
    }
    
    document.getElementById("errorMessage").innerHTML = "&nbsp;";
    //提交
    var url = "/user/companyIdentityValidate.do?random="+Math.round(Math.random()*100);
    var param={firstName:firstName,realName:realName,birthDate:birthDate,country:country,idNumber:idNumber,province:province,street:street,
    		city:city,build:build,unit:unit,postcode:postcode,previousName:previousName};
    jQuery.post(url,param,function(data){
        var result = eval('(' + data + ')');
        if(result!=null){
            if(result == -1){
                //非法的请求
                window.location.href= document.getElementById("coinMainUrl").value+"/";
            }else if(result == 0){
                //提交失败
                document.getElementById("errorMessage").innerHTML= get$("rechargeusdsubfailure");
            }else if(result == 101){
                //提交成功 国内
                window.location.href = document.getElementById("coinMainUrl").value+"/user/userinfo.do?random="+Math.round(Math.random()*100);
            }else if(result == 102){
                //提交成功 国际 继续董事与股东
                window.location.href= document.getElementById("coinMainUrl").value+"/user/companyIdentity.do";
            }else if(result == 103){
                //提交成功 国际 已完成董事与股东
                window.location.href= document.getElementById("coinMainUrl").value+"/user/foreignIndex.do";
            }else if(result == 2){
                //姓
                document.getElementById("errorMessage").innerHTML= get$("companyidentityjs1");
            }else if(result == 4){
                //真实姓名
                document.getElementById("errorMessage").innerHTML= get$("companyidentityjs5");
            }else if(result == 5){
                //注册日期
                document.getElementById("errorMessage").innerHTML= get$("companyidentityjs2");
            }else if(result == 9){
                //注册号
                document.getElementById("errorMessage").innerHTML= get$("companyidentityjs3");
            }else if(result == 10){
                //验证省份
                document.getElementById("errorMessage").innerHTML= userindexjs44;
            }else if(result == 11){
                //验证街道
                document.getElementById("errorMessage").innerHTML= userindexjs42;
            }else if(result == 12){
                //验证城市
                document.getElementById("errorMessage").innerHTML= userindexjs50;
            }else if(result == 13){
                //验证建筑号
                document.getElementById("errorMessage").innerHTML= get$("foreignIdentitybuildislong");
            }else if(result == 14){
                //验证单元号
                document.getElementById("errorMessage").innerHTML= get$("foreignIdentityunitislong");
            }else if(result == 15){
                //验证邮编
                document.getElementById("errorMessage").innerHTML= get$("userindexjs48");
            }else if(result == 16){
                //验证曾用名
                document.getElementById("errorMessage").innerHTML= get$("userindexjs52");
            }else if(result == 17){
                //验证国家
                document.getElementById("errorMessage").innerHTML= get$("foreignIdentitycannotverify");
            }
        }
    });
}

//选择认证身份flag 0个人，1企业;type 1国内，2国际
function userConforimSelect(flag,type){
//	jQuery("#userConforim"+flag).attr("class","userConforimBgCur");
//	var callback={
//			okBack:function(){
				if(type == 2){
					window.location.href= document.getElementById("coinMainUrl").value+"/user/foreignIndex.do?userFlag="+flag;
				}else{
					if(flag==0){
						window.location.href= document.getElementById("coinMainUrl").value+"/user/chinaIdentity.do?userFlag="+flag;
					}else{
						window.location.href= document.getElementById("coinMainUrl").value+"/user/companyIdentity.do?userFlag="+flag;
					}
				}
			//},
			//noBack:function(){
//				var href = window.location.href;
//				if(href.indexOf("userFlag=0") != -1){
//					jQuery("#personaltype").attr("checked","checked");
//				}else if(href.indexOf("userFlag=1") != -1){
//					jQuery("#companytype").attr("checked","checked");
//				}else{
//					jQuery("#personaltype").removeAttr("checked");
//					jQuery("#companytype").removeAttr("checked");
//				}
//				jQuery("#userConforim"+flag).attr("class","userConforimBg");
//				return false;
//			}
//		};
//	if(flag == 0){
//		okcoinAlert(userConforimSelect0,cancelled,callback,oksure);
//	}else{
//		okcoinAlert(userConforimSelect1,cancelled,callback,oksure);
//	}
}

//选择居住国家
function addressCountrySelect(address) {
    if(document.getElementById("postcodereqestflag").value == "1") {
        return;
    }
    document.getElementById("addressOpt").style.display = "none";
    document.getElementById("detailAddressOpt").style.display = "block";
    var postcode = trim(document.getElementById("postcode").value);
    if(",8,10,11,26,34,51,68,85,87,106,118,130,131,135,166,167,172,173,191,192,".indexOf(","+address+",")>=0) {
        document.getElementById("detailAddressSpan").innerHTML = get$("inputrightpostcode");
    }else {
        document.getElementById("detailAddressSpan").innerHTML = "<input id='detailAddress' name='detailAddress' type='text' class='inputStyle' />";
    }
    document.getElementById("province").value = "";
    document.getElementById("city").value = "";
    document.getElementById("street").value = "";
    document.getElementById("build").value = "";
    document.getElementById("unit").value = "";
}
function postcodefocus() {
    if(document.getElementById("postcodereqestflag").value == "1") {
        return;
    }
    var address = document.getElementById("address").value;
    if(",8,10,11,26,34,51,68,85,87,106,118,130,131,135,166,167,172,173,191,192,".indexOf(","+address+",")>=0) {
        document.getElementById("detailAddressSpan").innerHTML = get$("inputrightpostcode");
        document.getElementById("detailAddressOpt").style.display = "block";
        document.getElementById("addressOpt").style.display = "none";
        document.getElementById("province").value = "";
        document.getElementById("city").value = "";
        document.getElementById("street").value = "";
        document.getElementById("build").value = "";
        document.getElementById("unit").value = "";
    }
}
//根据邮编获取住址信息
function postcoding() {
    //当前居住国家
    var address = document.getElementById("address").value;
    if(",8,10,11,26,34,51,68,85,87,106,118,130,131,135,166,167,172,173,191,192,".indexOf(","+address+",")<0) {
        return;
    }
    if(document.getElementById("postcodereqestflag").value == "1") {
        return;
    }
    //邮编
    var postcode = trim(document.getElementById("postcode").value);
    var regexp = "";
    switch (parseInt(address)) {
        case 8:case 10:case 11:case 51:case 106:regexp = "^[0-9]{4}$";break;
        case 26:regexp = "^([0-9]{5})-([0-9]{3})$";break;
        case 34:regexp = "^[A-Za-z][0-9][A-Za-z][0-9][A-Za-z][0-9]$";break;
        case 68:case 87:case 118:regexp = "^[0-9]{5}$";break;
        case 85:regexp = "^[A-Za-z0-9\\-]{4,15}$";break;//爱尔兰
        case 130:regexp = "^([0-9]{4})([A-Za-z]{2})$";break;
        case 131:regexp = "^[0-9]{4}$";break;
        case 135:regexp = "^[0-9]{4}$";break;
        case 166:regexp = "^[A-Za-z0-9\\-]{4,15}$";break;//南非
        case 167:regexp = "^[0-9]{5}$";break;
        case 172:regexp = "^[0-9]{5}$";break;
        case 173:regexp = "^[0-9]{4}$";break;
        case 191:regexp = "^[A-Za-z0-9]{5,9}$";break;
        case 192:regexp = "^[0-9]{5}$";break;
        default :return;
    }
    if(!new RegExp(regexp).test(postcode)) {
        return;
    }
    document.getElementById("postcodereqestflag").value = "1";
    document.getElementById("detailAddressSpan").innerHTML = get$("addressinfoloading");
    var url = "/user/getAddressByPostcode.do?random="+Math.round(Math.random()*100);
    var param = {countryId:address,postCode:postcode};
    jQuery.post(url,param,function(data){
        document.getElementById("postcodereqestflag").value = "0";
        var result = data;
        if(result!=null){
            if(result == "500"){
                //非法的请求
                document.getElementById("detailAddressSpan").innerHTML = get$("addressinfoloadfail");
            }else{
//                var selects = "<select id=\"detailAddress\" style=\"width:398px;height:34px;\" onchange=\"postcodeSelect()\">";
//                for(var i=0;i< result.length;++i) {
//                    var pcs = result[i].split("@#@");
//                    if(i==0) {
//                        document.getElementById("province").value = pcs[0];
//                        document.getElementById("city").value = pcs[1];
//                        document.getElementById("street").value = pcs[2];
//                        document.getElementById("build").value = pcs[3];
//                    }
//                    selects += "<option value=\""+result[i]+"\">"+pcs[4]+"</option>";
//                }
//                selects += "</select>";
//                document.getElementById("detailAddressSpan").innerHTML = selects;
                var pcs = result.split("@#@");
                document.getElementById("province").value = pcs[0];
                document.getElementById("city").value = pcs[1];
                document.getElementById("street").value = pcs[2];
                document.getElementById("build").value = pcs[3];
                document.getElementById("detailAddressOpt").style.display = "none";
                document.getElementById("addressOpt").style.display = "block";
            }
        }
    });
}

function postcodeSelect() {
    var pcs = document.getElementById("detailAddress").value.split("@#@");
    document.getElementById("province").value = pcs[0];
    document.getElementById("city").value = pcs[1];
    document.getElementById("street").value = pcs[2];
    document.getElementById("build").value = pcs[3];
}

function addressBelongSure(){
	if(!document.getElementById("belongingAddressSure").checked){
		document.getElementById("submit").disabled=true;
		document.getElementById("submit").className="button_gray disagree";
	}else{
		document.getElementById("submit").disabled=false;
		document.getElementById("submit").className="buttonblue3 agree";
	}
}
function selectCountry(optionValue){
    var limitedCountries = document.getElementById('limitedCountryIds').value;
    if(limitedCountries.indexOf(","+optionValue+",")>=0) {
        document.getElementById('notSupportedCountry').style.display='block';
    }else {
        document.getElementById('notSupportedCountry').style.display='none';
    }
}
function judgingProvinces(provinceValue){
	if(provinceValue.indexOf("New York")>=0 || provinceValue == "NY" || provinceValue.indexOf("纽约")>=0 || provinceValue.indexOf("NewYork")>=0 || provinceValue.indexOf("new york")>=0 || provinceValue.indexOf("newyork")>=0){
        document.getElementById('judgingProvinces').style.display='block';
    }else {
    	document.getElementById('judgingProvinces').style.display='none';
    }
}

function checkBindEmail(){
	var email = document.getElementById("bindEmail").value;
	if(trim(email)==null||trim(email).length==0){
		document.getElementById("emailCodeTips").innerHTML=get$("userindexjs12");
		return ;
	}
	
	email = trim(email);
	
	if(!checkEmail(email)){
		document.getElementById("emailCodeTips").innerHTML=get$("userindexjs22");
		return ;
	}
	
	// 邮箱是否被使用
	url = "/user/checkEmailBeUsed.do?random="+Math.round(Math.random()*100);
	var param={email:email};
	jQuery.post(url,param,function(data){
		if(data==1){
			// 邮箱被使用
			document.getElementById("emailCodeTips").innerHTML=get$("userindexjs19");
		}else if(data==0){
			// 邮箱未被使用
			document.getElementById("emailCodeTips").innerHTML="";
		}else if(data==-1){
			document.getElementById("emailCodeTips").innerHTML=get$("userindexjs12");
		}
	});
	
}

//只允许输入字母
function checkEnglish(obj){
	obj.value = obj.value.replace(/[^a-zA-Z\.]/g,'');
}

//限制百分比输入
function limitPercentByObj(obj){
	var percent = checkNumberByObj(obj,2);
	if(percent!=""){
		if(percent>100){
			percent = 100;
		}
	}
	obj.value = percent;
}

//弹出新的股东表单
function addNewHolder(){
	
	var d = document, obj,tempStr = [], number;
	obj = d.createElement("div");
	obj.className="layerPop ";
	number = jQuery("#shareholderNumbers").val();
	jQuery("#addNewHolderBtn").hide();
	number++;
	
	if(number>10){
		return ;
	}

	tempStr.push('<span class="title">'+get$("companyidentityjs9")+number+'</span>');
	tempStr.push('<ul>');
	tempStr.push('<li>');
	tempStr.push('<span class="name">'+get$("companyidentityjs10")+'：</span>');
	tempStr.push('<span>');
	tempStr.push('<input type="hidden" id="holderType'+number+'" name="holderType'+number+'" value="1">');
	tempStr.push('<input type="radio" checked="checked" name="holderStatus'+number+'" value="1" onclick="javascript:selectHolderType(1,'+number+');"><span>'+get$("companyidentityjs11")+'</span>');
	tempStr.push('<input type="radio" class="company" name="holderStatus'+number+'" value="2" onclick="javascript:selectHolderType(2,'+number+');"><span>'+get$("companyidentityjs12")+'</span>');
	tempStr.push('<p class="tips" id="holderStatusTips'+number+'" style="display: none;">'+get$("companyidentityjs13")+'</p>');
	tempStr.push('</span></li>');
	tempStr.push('<li>');
	tempStr.push('<span class="name">'+get$("companyidentityjs14")+'：</span>');
	tempStr.push('<span class="setRight">');
	tempStr.push('<input type="text" id="ratio'+number+'" onkeyup="javascript:limitPercentByObj(this);">');
	tempStr.push('<span class="per">%</span>');
	tempStr.push('</span></li>');
	
	tempStr.push('<li id="firstNameLi'+number+'">');
	tempStr.push('<span class="name">'+get$("companyidentityjs15")+'：</span>');
	tempStr.push('<span>');
	tempStr.push('<input type="text" id="firstName'+number+'" onkeyup="javascript:checkEnglish(this);">');
	tempStr.push('</span></li>');
	tempStr.push('<li id="lastNameLi'+number+'">');
	tempStr.push('<span class="name"">'+get$("companyidentityjs16")+'：</span>');
	tempStr.push('<span>');
	tempStr.push('<input type="text" id="lastName'+number+'" onkeyup="javascript:checkEnglish(this);">');
	tempStr.push('</span></li>');
    tempStr.push('<li id="aliasLi'+number+'">');
    tempStr.push('<span class="name"">'+get$("companyidentityjs74")+'：</span>');
    tempStr.push('<span>');
    tempStr.push('<input type="text" id="alias'+number+'" onkeyup="javascript:checkEnglish(this);">');
    tempStr.push('</span></li>');
	
	tempStr.push('<li id="companyNameLi'+number+'" style="display:none;">');
	tempStr.push('<span class="name">'+get$("companyidentityjs17")+'：</span>');
	tempStr.push('<span>');
	tempStr.push('<input type="text" id="companyName'+number+'">');
	tempStr.push('</span></li>');
	tempStr.push('<li id="registrationNumberLi'+number+'" style="display:none;">');
	tempStr.push('<span class="name"">'+get$("companyidentityjs18")+'：</span>');
	tempStr.push('<span>');
	tempStr.push('<input type="text" id="registrationNumber'+number+'">');
	tempStr.push('</span></li>');
	tempStr.push('<li id="companyDocumentLi'+number+'" style="display:none;">');
	tempStr.push('<span class="name">'+get$("companyidentityjs19")+'：</span>');
	tempStr.push('<span>');
	tempStr.push('<span id="fileName'+number+'"></span>&nbsp;&nbsp;');
	tempStr.push('<input type="button" id="fileBtn'+number+'" value="'+get$("companyidentityjs20")+'" class="confirmBtn" onclick="javascript:selectImage(\'file'+number+'\');">');
	tempStr.push('<input id="file'+number+'" name="file'+number+'" type="file" accept=".pdf" onchange="javascript:checkHolderFile(this,'+number+');" style="display:none;"/>');
	tempStr.push('</span></li>');
	
	tempStr.push('</ul>');
	
	tempStr.push('<div class="addDirectors">');
	tempStr.push('<input id="shareholderId'+number+'" value="0" type="hidden">');
	tempStr.push('<span class="fred" id="holderMessage'+number+'"></span><br>');
	tempStr.push('<input class="button_blue" type="button" id="submitHoldereBtn'+number+'" id="submitHolder'+number+'" value="'+get$("companyidentityjs71")+'" onclick="javascript:companyShareholderSubmit('+number+');">');
	tempStr.push('<input class="button_blue" type="button" id="modifyHolderBtn'+number+'" style="display: none;" value="'+get$("passwordjs11")+'" onclick="javascript:modifyHolderInfo('+number+');">');
	tempStr.push('</div>');
	
	tempStr.push('</div>');
	obj.innerHTML=tempStr.join("");
	d.getElementById("shareholderInfo").appendChild(obj);
	jQuery("#shareholderNumbers").val(number);
	return true;
}

function selectHolderType(type, number){
	document.getElementById("holderType"+number).value=type;
	if(type==1){
		jQuery("#holderStatusTips"+number).hide();
		jQuery("#firstNameLi"+number).show();
		jQuery("#lastNameLi"+number).show();
		jQuery("#aliasLi"+number).show();
		jQuery("#companyNameLi"+number).hide();
		jQuery("#registrationNumberLi"+number).hide();
		jQuery("#companyDocumentLi"+number).hide();
	}else{
		jQuery("#holderStatusTips"+number).show();
		jQuery("#firstNameLi"+number).hide();
		jQuery("#lastNameLi"+number).hide();
		jQuery("#aliasLi"+number).hide();
		jQuery("#companyNameLi"+number).show();
		jQuery("#registrationNumberLi"+number).show();
		jQuery("#companyDocumentLi"+number).show();
	}
}

function modifyHolderInfo(number){
	// 显示修改按钮
	jQuery("#holderStatusTips" + number).show();
	jQuery("#modifyHolderBtn" + number).hide();
	jQuery("#submitHoldereBtn" + number).show();
	// 将股东资料设为只读
	jQuery("input[name='holderStatus"+number+"']").removeAttr("disabled");
	jQuery("#ratio"+number).removeAttr("readOnly");
	jQuery("#firstName"+number).removeAttr("readOnly");
	jQuery("#lastName"+number).removeAttr("readOnly");
    jQuery("#alias"+number).removeAttr("readOnly");
	jQuery("#companyName"+number).removeAttr("readOnly");
	jQuery("#registrationNumber"+number).removeAttr("readOnly");
	jQuery("#fileBtn" + number).show();
}

/**
 * 提交董事信息
 */
function companyDirectorSubmit(){
	document.getElementById("directorMessage").style.color = "red";// 将提示的颜色改为红色
	//董事甲 姓、名
	var firstNameA = trim(document.getElementById("firstNameA").value);
	if(firstNameA != "" && firstNameA.length >= 100){
		document.getElementById("directorMessage").innerHTML = get$("companyidentityjs22");
    	return;
	}
	var lastNameA = trim(document.getElementById("lastNameA").value);
	if(lastNameA != "" && lastNameA.length >= 100){
		document.getElementById("directorMessage").innerHTML = get$("companyidentityjs23");
    	return;
	}
    var aliasA = trim(document.getElementById("aliasA").value);
    if(aliasA != "" && aliasA.length >= 100){
        document.getElementById("directorMessage").innerHTML = get$("companyidentityjs75");
        return;
    }
	if(firstNameA!="" || lastNameA!=""){
		if(firstNameA=="" || lastNameA==""){
			document.getElementById("directorMessage").innerHTML = get$("companyidentityjs24");
	    	return;
		}
	}
	
	//董事乙 姓、名
	var firstNameB = trim(document.getElementById("firstNameB").value);
	if(firstNameB != "" && firstNameB.length >= 100){
		document.getElementById("directorMessage").innerHTML = get$("companyidentityjs25");	
    	return;
	}
	var lastNameB = trim(document.getElementById("lastNameB").value);
	if(lastNameB != "" && lastNameB.length >= 100){
		document.getElementById("directorMessage").innerHTML = get$("companyidentityjs26");	
    	return;
	}
    var aliasB = trim(document.getElementById("aliasB").value);
    if(aliasB != "" && aliasB.length >= 100){
        document.getElementById("directorMessage").innerHTML = get$("companyidentityjs76");
        return;
    }
	if(firstNameB!="" || lastNameB!=""){
		if(firstNameB=="" || lastNameB==""){
			document.getElementById("directorMessage").innerHTML = get$("companyidentityjs27");	
	    	return;
		}
	}
	
	// 至少要有一个董事信息
	if(firstNameA=="" && firstNameB==""){
		document.getElementById("directorMessage").innerHTML = get$("companyidentityjs28");	
    	return;
	}
	document.getElementById("shareholderIdentityMessage").innerHTML = "";
	document.getElementById("directorSubmitBtn").disable = true;
	
	var url = "/user/directorIdentityValidate.do?random="+Math.round(Math.random()*100);
	var param={firstNameA:firstNameA,lastNameA:lastNameA,firstNameB:firstNameB,lastNameB:lastNameB,aliasA:aliasA,aliasB:aliasB};
	jQuery.post(url,param,function(result){
		if(result==0){
			document.getElementById("directorMessage").style.color = "green";// 将提示的颜色改为绿色
			// 提交成功
			document.getElementById("directorMessage").innerHTML = get$("companyidentityjs29");
			// 成功处理
			jQuery("#directorSubmitBtn").hide();
			document.getElementById("firstNameA").setAttribute('readOnly',true);
			document.getElementById("lastNameA").setAttribute('readOnly',true);
			document.getElementById("aliasA").setAttribute('readOnly',true);
			document.getElementById("firstNameB").setAttribute('readOnly',true);
			document.getElementById("lastNameB").setAttribute('readOnly',true);
			document.getElementById("aliasB").setAttribute('readOnly',true);
		}else if(result==-1){
			// 无效的请求
			window.location.reload();
		}else if(result==-2){
			// 董事一信息不全
			document.getElementById("directorMessage").innerHTML = get$("companyidentityjs24");
		}else if(result==-3){
			// 董事一信息过长
			document.getElementById("directorMessage").innerHTML = get$("companyidentityjs30");
		}else if(result==-4){
			// 董事二信息不全
			document.getElementById("directorMessage").innerHTML = get$("companyidentityjs27");
		}else if(result==-5){
			// 董事二信息过长
			document.getElementById("directorMessage").innerHTML = get$("companyidentityjs31");
		}else if(result==-6){
			// 没有输入董事信息
			document.getElementById("directorMessage").innerHTML = get$("companyidentityjs28");
		}else{
			// 提交失败
			document.getElementById("directorMessage").innerHTML = get$("companyidentityjs32");
		}
		document.getElementById("directorSubmitBtn").disable = false;
	});
}


// 提交股东信息，number为股东序号
function companyShareholderSubmit(number){
	document.getElementById("holderMessage"+number).style.color = "red";// 将提示的颜色改为红色
	var shareholderId = document.getElementById("shareholderId"+number).value;
	var type = document.getElementById("holderType"+number).value;
	var ratio = document.getElementById("ratio"+number).value;
	var firstName = document.getElementById("firstName"+number).value;
	var lastName = document.getElementById("lastName"+number).value;
	var alias = document.getElementById("alias"+number).value;
	var companyName = document.getElementById("companyName"+number).value;
	var registrationNumber = document.getElementById("registrationNumber"+number).value;
	var selectFile = document.getElementById("file"+number);
	var file = selectFile.files[0];
	if(ratio==""){
		document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs33");
		return ;
	}
	if(isNaN(ratio)){
		document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs34");
		return ;
	}
	if(ratio<10){
		document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs35");
		return ;
	}
	if(ratio>100){
		document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs36");
		return ;
	}
	if(type==1){
		if(firstName==""){
			document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs37");
			return ;
		}
		if(firstName.length >= 100){
			document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs38");
			return ;
		}
		if(lastName==""){
			document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs39");
			return ;
		}
		if(lastName.length >= 100){
			document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs40");
			return ;
		}
        if(alias.length >= 100){
            document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs77");
            return ;
        }
	}else{
		if(companyName==""){
			document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs41");
			return ;
		}
		if(companyName.length >= 100){
			document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs42");
			return ;
		}
		if(registrationNumber==""){
			document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs43");
			return ;
		}
		if(registrationNumber.length >= 100){
			document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs44");
			return ;
		}
		
		if(!file){
			document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs45");
			return ;
		}
	}
	
	document.getElementById("holderMessage"+number).innerHTML = "";
	document.getElementById("shareholderIdentityMessage").innerHTML = "";
	//点击按钮后让其置灰不可点并出现动态小点点
	var buttonValue = document.getElementById("submitHoldereBtn" + number).value;		//先前按钮的值
	waitingStation("submitHoldereBtn" + number,get$("iddocument_submiting"));
	
	var formdata = new FormData();
	formdata.append("shareholderId", shareholderId);
	formdata.append("shareholderNo", number);
	formdata.append("type", type);
	formdata.append("ratio", ratio);
	formdata.append("firstName", firstName);
	formdata.append("lastName", lastName);
	formdata.append("alias", alias);
	formdata.append("companyName", companyName);
	formdata.append("registrationNumber", registrationNumber);
    formdata.append("documentFile", file);
	
    var currentAjax = jQuery.ajax({
		url : '/user/shareholderIdentityValidate.do',
		type : 'POST',
		data : formdata,
		dataType : 'JSON',
		cache : false,
		processData : false,
		contentType : false
    }).done(function(data) {
//		alert("data:"+data);
    	var result = -1;
    	result = data.result;
		if (result == 0) {
			// 记录股东id
			var shareholderId = data.shareholderId;
			document.getElementById("shareholderId"+number).value = shareholderId;
	    	
			// 显示修改按钮
			document.getElementById("holderMessage"+number).innerHTML = "";
			jQuery("#holderStatusTips" + number).hide();
			jQuery("#modifyHolderBtn" + number).show();
			jQuery("#submitHoldereBtn" + number).hide();
			var shareholderNumbers = document.getElementById("shareholderNumbers").value;
			if(number==shareholderNumbers){
				jQuery("#addNewHolderBtn").show();
			}
			// 将股东资料设为只读
			jQuery("input[name='holderStatus"+number+"']").attr({"disabled":"disabled"});
			document.getElementById("ratio"+number).setAttribute('readOnly',true);
			document.getElementById("firstName"+number).setAttribute('readOnly',true);
			document.getElementById("lastName"+number).setAttribute('readOnly',true);
			document.getElementById("alias"+number).setAttribute('readOnly',true);
			document.getElementById("companyName"+number).setAttribute('readOnly',true);
			document.getElementById("registrationNumber"+number).setAttribute('readOnly',true);
			jQuery("#fileBtn" + number).hide();
		}else{
			if (result == -1) {
				window.location.reload();
			} else if (result == -2) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs47");
			} else if (result == -3) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs47");
			} else if (result == -4) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs48");
			} else if (result == -5) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs49");
			} else if (result == -6) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs50");
			} else if (result == -15) {
                document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs78");
            } else if (result == -7) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs51");
			} else if (result == -8) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs52");
			} else if (result == -9) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs53");
			} else if (result == -10) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs53");
			} else if (result == -11) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs54");
			} else if (result == -12) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyfilesize10");
			} else if (result == -13) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs56");
			} else if (result == -14) {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs57");
			} else {
				document.getElementById("holderMessage"+number).innerHTML = get$("companyidentityjs56");
			}
		}

		//恢复按钮让其可点击并去掉小点点
		cancelWaiting("submitHoldereBtn" + number,buttonValue);
    });
}

/**
 * 确定董事与股东信息
 */
function shareholderIdentitySubmit(){
	// 判断所有的股东信息是否填写，否则提示
	var number = jQuery("#shareholderNumbers").val();
	var ratioSum = 0;
	for(var i=1;i<number;i++){
		if(jQuery("#modifyHolderBtn"+i).is(':hidden')){
			// 有股东未提交
			document.getElementById("shareholderIdentityMessage").innerHTML = get$("companyidentityjs9")+i+get$("companyidentityjs72");
			return ;
		}
		var ratio = document.getElementById("ratio"+i).value;
		ratioSum = parseInt(ratioSum) + parseInt(ratio);
	}
	if(document.getElementById("holderType"+number)){
		var type = document.getElementById("holderType"+number).value;
		var ratio = document.getElementById("ratio"+number).value;
		var firstName = document.getElementById("firstName"+number).value;
		var lastName = document.getElementById("lastName"+number).value;
		var alias = document.getElementById("alias"+number).value;
		var companyName = document.getElementById("companyName"+number).value;
		var registrationNumber = document.getElementById("registrationNumber"+number).value;
		var selectFile = document.getElementById("file"+number);
		var file = selectFile.files[0];
		// 如果填写过最后的股东信息，则尝试提交股东信息
		if(type==1){
			if(ratio!="" || firstName!="" || lastName!=""){
				ratioSum = parseInt(ratioSum) + parseInt(ratio);
				if(jQuery("#modifyHolderBtn"+number).is(':hidden')){
					// 有股东未提交
					document.getElementById("shareholderIdentityMessage").innerHTML = get$("companyidentityjs9")+number+get$("companyidentityjs72");
					return ;
				}
			}
		}else{
			if(ratio!="" || companyName!="" || registrationNumber!="" || !file){
				ratioSum = parseInt(ratioSum) + parseInt(ratio);
				if(jQuery("#modifyHolderBtn"+number).is(':hidden')){
					// 有股东未提交
					document.getElementById("shareholderIdentityMessage").innerHTML = get$("companyidentityjs9")+number+get$("companyidentityjs72");
					return ;
				}
			}
		}
	}
	
	// 判断所有的股东的持股比例之和
	if(ratioSum>100){
		document.getElementById("shareholderIdentityMessage").innerHTML = get$("companyidentityjs73");
		return ;
	}
    if(ratioSum<=0){
        document.getElementById("shareholderIdentityMessage").innerHTML = get$("companyidentityjs59");
        return ;
    }
	document.getElementById("shareholderIdentityMessage").innerHTML = "";
	document.getElementById("shareholderIdentitySubmitBtn").disable = true;
	
	var url = "/user/shareholderIdentitySubmit.do?random="+Math.round(Math.random()*100);
	jQuery.post(url,null,function(result){
		if(result==0){
			// 提交成功 跳转页面
			window.location.href=document.getElementById("coinMainUrl").value + "/user/foreignIndex.do";
		}else if(result==-1){
			// 无效的请求
			window.location.reload();
		}else if(result==-2){
			// 董事信息未提交
			document.getElementById("shareholderIdentityMessage").innerHTML = get$("companyidentityjs58");
		}else if(result==-3){
			// 股东信息未提交
			document.getElementById("shareholderIdentityMessage").innerHTML = get$("companyidentityjs59");
		}else if(result==-4){
			// 股东信息持股比例总和超过100%
			document.getElementById("shareholderIdentityMessage").innerHTML = get$("companyidentityjs73");
		}else{
			// 提交失败
			document.getElementById("shareholderIdentityMessage").innerHTML = get$("companyidentityjs60");
		}
		document.getElementById("shareholderIdentitySubmitBtn").disable = false;
	});
}

/**
 * 提交公司简介
 */
function companyIntroduceSubmit(){
	document.getElementById("errorTips_0").style.color = "red";// 将提示的颜色改为红色
	// 简介内容
	var majorBusiness = trim(document.getElementById("majorBusiness").value);
	var capitalSource = trim(document.getElementById("capitalSource").value);
	var tradeScheme = trim(document.getElementById("tradeScheme").value);
	if(majorBusiness == ""){
		document.getElementById("errorTips_0").innerHTML = get$("companyidentityjs61");
    	return;
	}
	if(majorBusiness.length > 480){
		document.getElementById("errorTips_0").innerHTML = get$("companyidentityjs62");
    	return;
	}
	if(capitalSource == ""){
		document.getElementById("errorTips_0").innerHTML = get$("companyidentityjs63");
    	return;
	}
	if(capitalSource.length > 480){
		document.getElementById("errorTips_0").innerHTML = get$("companyidentityjs64");
    	return;
	}
	if(tradeScheme == ""){
		document.getElementById("errorTips_0").innerHTML = get$("companyidentityjs65");
    	return;
	}
	if(tradeScheme.length > 480){
		document.getElementById("errorTips_0").innerHTML = get$("companyidentityjs66");
    	return;
	}
	
	document.getElementById("introduceSubmitBtn").disable = true;
	
	var url = "/user/companyIntroduceSubmit.do?random="+Math.round(Math.random()*100);
	var param={majorBusiness:majorBusiness,capitalSource:capitalSource,tradeScheme:tradeScheme};
	jQuery.post(url,param,function(result){
		if(result==0){
			document.getElementById("errorTips_0").style.color = "green";// 将提示的颜色改为绿色
			// 提交成功
			document.getElementById("errorTips_0").innerHTML = get$("companyidentityjs67");
			// 成功处理
			jQuery("#introduceSubmitBtn").hide();
			document.getElementById("majorBusiness").setAttribute('readOnly',true);
			document.getElementById("capitalSource").setAttribute('readOnly',true);
			document.getElementById("tradeScheme").setAttribute('readOnly',true);
		}else if(result==-1){
			// 无效的请求
			window.location.reload();
		}else if(result==-2){
			// 已经提交过简介
			window.location.reload();
		}else if(result==-3){
			// 主要业务不合法
			document.getElementById("errorTips_0").innerHTML = get$("companyidentityjs62");
		}else if(result==-4){
			// 资金来源不合法
			document.getElementById("errorTips_0").innerHTML = get$("companyidentityjs64");
		}else if(result==-5){
			// 交易计划不合法
			document.getElementById("errorTips_0").innerHTML = get$("companyidentityjs66");
		}else{
			// 提交失败
			document.getElementById("errorTips_0").innerHTML = get$("companyidentityjs68");
		}
		document.getElementById("introduceSubmitBtn").disable = false;
	});
}

/**
 * 提交基本认证
 */
function submitForeignBaseIdentity(){
    //姓
    var firstName = document.getElementById("firstName").value;
    if(firstName == ""){
        document.getElementById("errorMessage").innerHTML = get$("foreignIdentityfirstname");
        return;
    }
    if(firstName.length >= 100){
        document.getElementById("errorMessage").innerHTML = get$("foreignIdentityfirstnameislong");
        return;
    }
    //名
    var lastName = document.getElementById("lastName").value;
    if(lastName == ""){
        document.getElementById("errorMessage").innerHTML = get$("foreignIdentitylastname");
        return;
    }
    if(lastName.length >= 100){
        document.getElementById("errorMessage").innerHTML = get$("foreignIdentitylastnameislong");
        return;
    }
    //国籍
    var country = document.getElementById("country").value;
    var limitedCountries = document.getElementById('limitedCountryIds').value;
    if(limitedCountries.indexOf(","+country+",")>=0) {
        document.getElementById("errorMessage").innerHTML = get$("foreignIdentitycannotverify");
        return;
    }
    //无美国国籍
    var nousanationality = document.getElementById("nousanationality").checked;
    if(country == 192){
        nousanationality = 1;
    }else{
        if(document.getElementById("nousanationality").checked){
            nousanationality = 0;
        }else{
            nousanationality = 1;
        }
    }
    if(",4,11,12,14,25,28,39,40,50,51,55,60,62,81,82,83,89,91,92,93,95,96,99,105,111,117,118,126,129,130,135,140,142,144,161,162,164,178,190,197,201,".indexOf(","+country+",")>=0) {
        nousanationality = 0;
    }

    //护照号
    var passport = trim(document.getElementById("passport").value);
    if(country != "0" && passport == ""){
        document.getElementById("errorMessage").innerHTML = get$("foreignIdentitypassport");
        return;
    }else{
        document.getElementById("errorMessage").innerHTML = "&nbsp;";
    }
    if(country != "0" && passport.length <= 5){
        document.getElementById("errorMessage").innerHTML = get$("foreignIdentitypassportisshort");
        return;
    }
    if(country != "0" && passport.length >= 30){
        document.getElementById("errorMessage").innerHTML = get$("foreignIdentitypassportislong");
        return;
    }

    //提交
    var url = "/user/foreignBaseIdentityValidate.do?random="+Math.round(Math.random()*100);
    var param={firstName:firstName,lastName:lastName,country:country,nousanationality:nousanationality,
        passport:passport};
    jQuery.post(url,param,function(data){
        var result = eval('(' + data + ')');
        if(result!=null){
            if(result == -1){
                //非法的请求
                window.location.href= document.getElementById("coinMainUrl").value+"/";
            }else if(result == 0){
                //提交失败
                document.getElementById("errorMessage").innerHTML= get$("rechargeusdsubfailure");
            }else if(result == 1){
                //提交成功
                window.location.href= document.getElementById("coinMainUrl").value+"/user/foreignIndex.do";
            }else if(result == 111){
                //提交成功
                var papersType = document.getElementById("papersType").value;
                window.location.href = document.getElementById("coinMainUrl").value+"/user/residenceDocument.do?papersType="+papersType+"&random="+Math.round(Math.random()*100);
            }else if(result == 1111){
                //提交成功
                window.location.href= document.getElementById("coinMainUrl").value+"/user/userinfo.do";
            }else if(result == 2){
                //姓
                document.getElementById("errorMessage").innerHTML= get$("foreignIdentityfirstnameislong");
            }else if(result == 3){
                //名
                document.getElementById("errorMessage").innerHTML= get$("foreignIdentitylastnameislong");
            }else if(result == 21){
                //曾用名、别名
                document.getElementById("errorMessage").innerHTML= get$("foreignIdentitypreviousnameislong");
            }else if(result == 5){
                //出生日期
                document.getElementById("errorMessage").innerHTML= get$("foreignIdentitybirthdate");
            }else if(result == 6){
                //护照号
                document.getElementById("errorMessage").innerHTML= get$("foreignIdentitypassportislong");
            }else if(result == 7){
                //发证日期
                document.getElementById("errorMessage").innerHTML= get$("foreignIdentitystartdate");
            }else if(result == 8){
                //截止日期
                document.getElementById("errorMessage").innerHTML= get$("foreignIdentityenddate");
            }else if(result == 9){
                //身份证号
                document.getElementById("errorMessage").innerHTML= get$("foreignIdentityidnumberislong");
            }else if(result == 16){
                //中国用户身份证验证
                document.getElementById("errorMessage").innerHTML= get$("wrongidnumber");
            }else if(result == 17) {
                document.getElementById("errorMessage").innerHTML= get$("inputrightpostcodenotnull");
            }else if(result == 18) {
                document.getElementById("errorMessage").innerHTML= get$("inputaddressinfodetail");
            }else if(result == 19) {
                document.getElementById("errorMessage").innerHTML = get$("foreignIdentitycannotverify");
            }else if(result == 20) {
                document.getElementById("errorMessage").innerHTML = get$("peopleunder18");
            }else if(result == 22){
                //护照号重复
                document.getElementById("errorMessage").innerHTML = get$("passportisused");
            }else if(result == 23){
                //手机号不合法
                document.getElementById("errorMessage").innerHTML = get$("coincommonjs23");
            }
        }
    });
}